-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: xray watch #211
Feature: xray watch #211
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ |
I have read the CLA Document and I hereby sign the CLA |
recheckcla |
Hi @eyalbe4, it would be good to get your review on this. Cheers |
Sure @josh-barker-coles. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't gone through everything yet. Releasing what I have so far.
if *DistUrl != "" { | ||
createDistributionManager() | ||
} | ||
if *XrayUrl != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that this has been added as part of the InitArtifactoryServiceManager function, we should probably rename the function from InitArtifactoryServiceManager to InitServiceManagers.
@@ -158,6 +167,14 @@ func createDistributionManager() { | |||
testsBundleDeleteRemoteService.DistDetails = distDetails | |||
} | |||
|
|||
func createXrayManager() { | |||
xrayDetails := GetXrayDetails() | |||
client, err := rthttpclient.ArtifactoryClientBuilder().SetServiceDetails(&xrayDetails).Build() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that ArtifactoryClientBuilder also needs to be used for Xray, we should rename it to HttpClientBuilder.
We should also move the httpclient package, which is currently located under the artifactory directory, to be one level up, next to the artifactory dir.
rthttpclient should be renamed to httpclient, or if the the httpclient is already taken as an alias in the file, maybe jfroghttpclient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @eyalbe4,
I understand why you want to move that functionality, but I've noticed a few things.
- In the root directory, there already is a generic httpclient package, which ArtifactoryHttpClient depends on.
- The Distribution manager is also depend on the ArtifactoryClientBuilder
This sounds like a big change that should go in a separate PR, as it would effect many files under artifactory/*
, distribution/*
, tests/*
and xray/*
.
As the httpclient
directory & package is already taken, what did you want to do?
Cheers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it @josh-barker-coles. We'll create an issue for this and handle this in a follow up PR.
tests/utils.go
Outdated
@@ -158,6 +167,14 @@ func createDistributionManager() { | |||
testsBundleDeleteRemoteService.DistDetails = distDetails | |||
} | |||
|
|||
func createXrayManager() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, this function should be renamed to * createXrayVersionManager*.
xray/services/utils/xraywatchbody.go
Outdated
AssignedPolicies []XrayAssignedPolicy `json:"assigned_policies,omitempty"` | ||
} | ||
|
||
// structs that aren't exported |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "exported" mean?
BTW, our convention is is to start all comments with an upper case letter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eyalbe4
If a struct or function starts with an upper case, it's available in the package to be imported somewhere else.
However, if a struct or function starts with a lower case, it's internal and cannot be imported elsewhere.
As these structs are used for internally transforming the parameters to the payload, I opted to not export them.
What would you prefer?
xray/services/utils/xraywatchbody.go
Outdated
payloadBody.ProjectResources.Resources = append(payloadBody.ProjectResources.Resources, repo) | ||
} | ||
case "": | ||
// empty is fine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// empty is fine --> // Empty is fine
xray/services/utils/xraywatchbody.go
Outdated
case "": | ||
// empty is fine | ||
default: | ||
return errors.New("Invalid Repository Type. Must be " + string(WatchRepositoriesAll) + " or " + string(WatchRepositoriesByName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should wrap this error with errorutils.CheckError(err)
..
In this case, the above line should:
errorutils.CheckError(errors.New("Invalid Repository Type. Must be " + string(WatchRepositoriesAll) + " or " + string(WatchRepositoriesByName)))
errorutils.CheckError
is used to wrap the error when it is created by the code, or if it is created by the code of an external package, the error is wrapped the first time it is returned in the code. This approach allows us to track the source code generating the error if needed.
I noticed there's one more place in this file where this si needed.
xray/services/utils/xraywatchbody.go
Outdated
return nil | ||
} | ||
|
||
func configureBundles(payloadBody *XrayWatchBody, params XrayWatchParams) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We prefer not to have placeholder code in the form of empty methods. I suggest you to the description of the CreateBody
function a comment saying that bundles are currently not supported. This disclaimer should also be added to the API description in the README.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done reviewing everything.
Thanks so much for adding this!
See my inline comments.
tests/xraywatch_test.go
Outdated
assert.Equal(t, params.Description, targetConfig.Description) | ||
assert.Equal(t, params.Active, targetConfig.Active) | ||
assert.Equal(t, params.Policies, targetConfig.Policies) | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant return statement.
tests/xraywatch_test.go
Outdated
artUtils.SetContentType("application/json", &xrayHTTPDetails.Headers) | ||
client, err := httpclient.ClientBuilder().Build() | ||
if err != nil { | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be fixed to return err
.
resp, _, err := client.SendDelete(xrayDetails.GetUrl()+"api/v2/policies/"+policyName, nil, xrayHTTPDetails) | ||
if err != nil || resp.StatusCode != http.StatusOK { | ||
return errors.New("failed to delete policy " + resp.Status) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest changing the above to:
if err != nil {
return error
}
if resp.StatusCode != http.StatusOK {
return errors.New("failed to delete policy " + resp.Status)
}
This also applies to other checks in this file.
xray/services/xraywatch.go
Outdated
"net/http" | ||
|
||
rthttpclient "github.com/jfrog/jfrog-client-go/artifactory/httpclient" | ||
// "github.com/jfrog/jfrog-client-go/artifactory/services/utils" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this commented line.
xray/services/xraywatch.go
Outdated
) | ||
|
||
// XrayWatchService defines the http client and xray details | ||
type XrayWatchService struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ket's rename the struct to WatchService
and this file to watch.go
.
Let's also rename NewXrayWatchService
to NewWatchService
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most, if not all, structs have a prefix of Xray
.
Did you want them all to be renamed without Xray?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @eyalbe4, I've renamed all structs & functions that included Xray.
xray/services/xraywatch.go
Outdated
return nil | ||
} | ||
|
||
// Get retrieves the details about an Xray watch by name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Get retrieves the details about an Xray watch by name --> // Get retrieves the details of an Xray watch by its name.
xray/manager.go
Outdated
} | ||
|
||
// GetXrayVersion will return the xray version | ||
func (sm *XrayServicesManager) GetXrayVersion() (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename GetXrayVersion()
to GetVersion()
, CreateXrayWatch
to CreateWatch
and so on.
README.md
Outdated
- [Creating an Xray Watch](#creating-an-xray-watch) | ||
- [Get an Xray Watch](#get-an-xray-watch) | ||
- [Update an Xray Watch](#update-an-xray-watch) | ||
- [Delete an Xray Watch](#delete-an-xray-watch) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also include the new version API in the README.
README.md
Outdated
```go | ||
serviceConfig, err := config.NewConfigBuilder(). | ||
SetServiceDetails(rtDetails). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rtDetails --> xrayDetails
README.md
Outdated
SetCertificatesPath(certPath). | ||
SetThreads(threads). | ||
SetDryRun(false). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let'e remove SetThreads
andSetDryRun
Hey @eyalbe4, thanks for the feedback. I'll start working on it this week. |
Hi @eyalbe4, I'll fix the README conflict after we've resolved all the above discussions. |
Hi @eyalbe4, what else is remaining for this PR? Cheers, Josh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for this awesome contribution @josh-barker-coles!
Please go ahead and resolve the conflict, and I'll merge this PR.
2333d60
to
bc2aa2f
Compare
You're welcome @eyalbe4. I've just rebased & resolved the README.md issue. |
@josh-barker-coles Before the change: func (xws *WatchService) Delete(watchName string) (*http.Response, error)
func (xws *WatchService) Create(params utils.WatchParams) (*http.Response, error)
func (xws *WatchService) Update(params utils.WatchParams) (*http.Response, error)
func (xws *WatchService) Get(watchName string) (watchResp *utils.WatchParams, resp *http.Response, err error) After that changes: func (xws *WatchService) Delete(watchName string) error
func (xws *WatchService) Create(params utils.WatchParams) error
func (xws *WatchService) Update(params utils.WatchParams) error
func (xws *WatchService) Get(watchName string) (watchResp *utils.WatchParams, err error) We hope for your understanding. |
Hi @yahavi Thanks for letting me know. Although an error indicates that something has gone wrong, it limits the ability of consumers to handle error conditions. The implication of removing the HTTP response will force consumers to write their own code to parse the string and attempt to handle the generic error. Additionally, this design decision has wider implications for the artifactory terraform provider https://github.com/jfrog/terraform-provider-artifactory as the future goal is to refactor it to use this client library. Looking forward to your responses |
Thank you for sharing this input @josh-barker-coles. |
Hi @eyalbe4, no worries. It might be good to discuss with the maintainers of https://github.com/jfrog/terraform-provider-artifactory to see how that could work. Cheers |
Description:
This PR creates:
GetXrayVersion
CreateXrayWatch
GetXrayWatch
UpdateXrayWatch
DeleteXrayWatch
The Xray Watch functions support the configuration of Repositories and Builds.
There is a placeholder method to configure Bundles.
I can't implement the support for Bundles because of the limits on the free trial for artifactory.
Related Issues
Resolves #202